﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <meta charset='utf8'/>
    <link rel="stylesheet" type="text/css" href="/static/admin/css/public.css">
</head>

<body>

<div id="main">
    <h2>编辑新闻</h2>
    <form  id="login" action="{:url('add')}" method="post">
        <table border="0" cellspacing="10" cellpadding="0">
            <tr>
                <td>新闻标题：</td>
                <td><input type="text" name="title" value="{$row.title}" class="txt"/></td>
            </tr>
            <tr>
                <td>新闻图片：</td>
                <td>
                    <input type="file" id="file" ><img id="preview" src="{$row.pic_url}" style="display: block;width: 75px;"  alt="">
                    <button onclick="upload(event)">上传图片</button>
                        <!--  表单的隐藏域保存上传成功的图片地址 -->
                    <input type="hidden" name="pic_url" value="{$row.pic_url}">
                </td>
            </tr>
            <tr>
                <td>新闻分类：</td>
                <td><select class="s1" name='cate_id'>
                    {volist name="cate" id="v"}
                    {if $v.id==$row.cate_id}
                    <option selected value="{$v.id}">{$v.cate_name}</option>
                    {else /}
                    <option value="{$v.id}">{$v.cate_name}</option>
                    {/if}
                    {/volist}
                </select>
                </td>
            </tr>
            <tr>
                <td>新闻内容：</td>
                <td>
                    <div id="div1">
                    </div>
                    <textarea id="content" style="display: none" name="content" class="textarea"></textarea>
                </td>
            </tr>
            <tr>
                <td>添加人：</td>
                <td><input type="text" name="author" value="{$row.author}"  class="txt"/></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><input  onclick="add(event)" type="submit" value="修 改" class="sub"/><input type="reset" value="重 置" class="res"/></td>
            </tr>
        </table>
    </form>
</div>
<!-- 引入jQuery-->
<script src="/static/js/jquery.js"></script>
<!--引入在线文本编辑器-->
<script src="/static/js/wangEditor.js"></script>
<script type="text/javascript">
    //获取传递的数据,使用php的语法，注意外面是单引号，htmlspecialchars_decode()避免把特殊字符进行转码
    const content='<?php  echo  htmlspecialchars_decode($row["content"]); ?>';
    const E = window.wangEditor;
    const editor = new E('#div1');
    //获取textarea
    const $text1 = $('#content');
    editor.config.onchange = function (html) {
        // 第二步，监控变化，同步更新到 textarea
        $text1.val(html)  //给textarea赋值
    }
    editor.create()
    // 给编辑器编辑器内容
    editor.txt.html(content)
    //给文本框初始值
    $text1.val(editor.txt.html())
</script>
<script src="/static/admin/js/news_add.js"></script>


</body>
</html>
